package com.sxhuayuan.parking.service.impl;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;

import com.sxhuayuan.parking.dao.BaseDao;
import com.sxhuayuan.parking.dao.OriginalParkingInfoDao;
import com.sxhuayuan.parking.entity.OriginalParkingInfo;
import com.sxhuayuan.parking.service.OriginalParkingInfoService;

@Service("originalParkingInfoServiceImpl")
public class OriginalParkingInfoServiceImpl extends BaseServiceImpl<OriginalParkingInfo, Long> implements OriginalParkingInfoService {

	@Autowired
	OriginalParkingInfoDao dao;

	@Override
	public BaseDao<OriginalParkingInfo, Long> getDAO() {
		return dao;
	}

	@Override
	public OriginalParkingInfo findByParkingLotOrderNo(String orderNo) {
		return dao.findByParkingLotOrderNo(orderNo);
	}

	@Override
	public boolean exists(String lotOrderNo) {
		long count = dao.count(new Specification<OriginalParkingInfo>() {
			private static final long serialVersionUID = 1L;

			@Override
			public Predicate toPredicate(Root<OriginalParkingInfo> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
				return cb.equal(root.get("lotOrderNo"), lotOrderNo);
			}
		});
		return count > 0;
	}
}
